import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
import * as mongoose from 'mongoose';

export enum ThemeMode {
    LIGHT = 'light',
    DARK = 'dark',
    SYSTEM = 'system',
}

@Schema({
    timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
    toJSON: {
        transform: (_, ret) => {
            ret.id = ret._id;
            delete ret._id;
            delete ret.__v;
            return ret;
        }
    }
})
export class UserSetting extends Document {
    @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'User', unique: true })
    user_id: string;

    @Prop({ type: String, enum: Object.values(ThemeMode), default: ThemeMode.SYSTEM })
    theme_mode: ThemeMode;

    @Prop({ default: true })
    email_notifications: boolean;

    @Prop({ default: true })
    show_tooltips: boolean;

    @Prop({ default: 'zh-CN' })
    language: string;

    @Prop({ type: mongoose.Schema.Types.Mixed, default: {} })
    advanced_settings: any;

    @Prop()
    created_at: Date;

    @Prop()
    updated_at: Date;
}

export const UserSettingSchema = SchemaFactory.createForClass(UserSetting); 